package com.ddwl.data.controller;

import com.ddwl.common.controller.BaseController;
import com.ddwl.common.util.SnowflakeIdGenerator;
import com.ddwl.common.util.UUIDGenerator;
import com.ddwl.schema.vo.base.RestVo;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2020/12/31 16:27
 */
@Api(tags = "雪花id生成测试")
@RequestMapping("/idGenerator")
@RestController
public class IdController extends BaseController {

    @Resource
    private SnowflakeIdGenerator idGenerator;

    @GetMapping("/getId")
    public RestVo<String> getId(){
        return RestVo.ok(UUIDGenerator.getShortUUID());
    }

    @GetMapping("/getIdList")
    public RestVo<List<Long>> getIdList(){
        List<Long> list = new ArrayList();
        for(int i=0;i<10;i++){
            list.add(idGenerator.nextId());
        }
        return RestVo.ok(list);
    }

    @GetMapping("/parseId/{uid}")
    public RestVo<String> parseId(@PathVariable("uid") Long uid){
        return RestVo.ok(idGenerator.parse(uid));
    }

}
